package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Controoler {
    @Autowired
    ServiceMapper serviceMapper;
    @RequestMapping("/show")
   public Object show(String nowDate){
       List<Map> show = serviceMapper.show(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",show.get(0).get("total"));
        return jsonObject;
   }
   //省份热力图
    @RequestMapping("/findTotal")
    public Object findTotal(){
        List<Map> total = serviceMapper.findTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray objects = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        for (Map map : total) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("name",map.get("name"));
            jsonObject2.put("value",map.get("total"));
            objects.add(jsonObject2);
        }
        jsonObject1.put("mapData",objects);
        jsonObject.put("data",jsonObject1);
        return jsonObject;
    }
    @RequestMapping("/zhan")
    public Object zhan(){
        List<Map> zhan = serviceMapper.zhan();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject jsonObject1 = new JSONObject();

        jsonObject.put("data",jsonObject1);


        return jsonObject;

    }
}